package com.hanock.sm.fork2d;

import java.util.ArrayList;
import java.util.List;

public class ButtonSetNode extends Node {

	
	private List<Node> tempList;
	
	public ButtonSetNode() {
		tempList = new ArrayList<Node>();
	}
	
	@Override
	public boolean visit(float x, float y, TouchMode mode) {
		
		
		
		
		if (mode == TouchMode.DOWN){
			
			List<Node> childList = getChildList();
			tempList.clear();
			tempList.addAll(childList);
			
			boolean selected = false;
			
			for (int i = 0; i < tempList.size(); i++){
				Node node = tempList.get(i);
				
				if (!selected && node instanceof Button){
					Button btn = (Button)node; 
					
					if (btn.isInTouchRect(x, y)){
						node.setZOrder(-1);
						selected = true;
					}
					else{
						node.setZOrder(-2);
					}
				}
				else{
					node.setZOrder(-2);
				}
			}
			
			tempList.clear();
		}
		
		return super.visit(x, y, mode);
	}

}





